package com.bw.finance.conf;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * resttemplate 配置
 */
@Configuration
public class RestTemplateConfig {

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(ClientHttpRequestFactory factory) {
        return new RestTemplate(factory);
    }

    @Bean
    public SimpleClientHttpRequestFactory simpleClientHttpRequestFactory() {

        SimpleClientHttpRequestFactory facotry = new SimpleClientHttpRequestFactory();
        /*10s*/
        facotry.setReadTimeout(10000);
        /*30s*/
        facotry.setConnectTimeout(30000);
        return facotry;
    }
}